﻿#!/usr/bin/env python3

import socket
import sys

def main():
    '''echo udp client -'''
    print(main.__doc__)
    print("="*30)

    HOST = 'localhost'                 # Symbolic name meaning all available interfaces
    PORT = 1000              # Arbitrary non-privileged port
    serveraddr = (HOST, PORT)
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.settimeout(10)
    msg = b"hello, the word."
    try:
        print("sending '%s'"%msg)
        sent = s.sendto(msg, serveraddr)
        print("waiting to receive.")
        data, server = s.recvfrom(4096)
        print("received '%s'  from %s" % (data, server))
    finally:
        print("close socket")
        s.close()


if __name__=='__main__':
    main()
